<template>
  <div id="box">
    
    <el-card class="box-card" >
        <div class="title">欢迎登录</div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-position="right"  label-width="80px" class="demo-ruleForm">
        <el-form-item label="账号" prop="account">
            <el-input v-model="ruleForm.account"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="ruleForm.password"></el-input>
        </el-form-item>
        <div id="sw">
            <el-switch inactive-text="记住密码" v-model="ruleForm.delivery"></el-switch>
        </div>
            <el-button type="primary" style="width:100%" @click="submitForm('ruleForm')">立即创建</el-button>
        </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
    data() {
      return {
        ruleForm: {
          account: '',
          password: '',
          delivery: false
        },
        rules: {
          account: [
            { required: true, message: '请输入账号8-12位字符', trigger: 'blur' },
            { min: 8, max: 12, message: '长度在 8 到 12 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 3, message: '长度至少8位', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>

<style>
#box{
    width: 400px;
    height: 300px;
    margin: 240px auto;
}
#sw{
    text-align: center;
    margin-bottom: 20px;
}
.box-card{
    width: 400px;
    height: 300px;
    margin: 0;
}
.title{
    text-align: center;
    font-size: 17px;
    color: dimgray;
    margin-bottom: 20px;
}
.el-form-item__label{
    padding: 0 33px 0 0;
}
</style>